package com.cipta.lomob.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cipta.lomob.R;
import com.cipta.lomob.base.BaseFragment;
import com.cipta.lomob.model.ItemVideo;

public class PopularVideoFragment extends BaseFragment{
	private static final String POPULAR_VIDEO = "PopularVideo";
	
	private ImageView imgVideo;
	private TextView txtUsername, txtTitle, txtFollowers, txtWatching;
	
	private ItemVideo itemVideo;
	
	public static PopularVideoFragment newInstance(ItemVideo itemVideo) {
		// TODO Auto-generated constructor stub
		final PopularVideoFragment popularVideoFragment = new PopularVideoFragment();
		final Bundle bundle = new Bundle();
		bundle.putSerializable(POPULAR_VIDEO, itemVideo);
		popularVideoFragment.setArguments(bundle);
		return popularVideoFragment;
	}
	
	public PopularVideoFragment() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		itemVideo = (ItemVideo) (getArguments() != null ? getArguments().getSerializable(POPULAR_VIDEO) : null);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_home_popular_video, container, false);
		initializeViews(view);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		initializeProcess();
	}
	
	@Override
	public void initializeViews(View view) {
		// TODO Auto-generated method stub
		super.initializeViews(view);
		
		imgVideo = (ImageView)view.findViewById(R.id.img_home_popular_video);
		txtTitle = (TextView)view.findViewById(R.id.txt_home_popular_video_title);
		txtUsername = (TextView)view.findViewById(R.id.txt_home_popular_video_username);
		txtWatching = (TextView)view.findViewById(R.id.txt_home_popular_video_total_watching);
		txtFollowers = (TextView)view.findViewById(R.id.txt_home_popular_video_total_followers);
	}
	
	@Override
	public void initializeProcess() {
		// TODO Auto-generated method stub
		super.initializeProcess();
		
		imgVideo.setImageResource(itemVideo.getThumbnails());
		txtTitle.setText(itemVideo.getTitle());
		txtUsername.setText(itemVideo.getUsers().getName());
		txtFollowers.setText("Followers "+itemVideo.getUsers().getTotalFollowers());
		txtWatching.setText("Watching "+itemVideo.getTotalWatching());
	}
	
}
